package com.zsrt.java.day20161226.zsh.demo01;

import java.util.Scanner;

public class CalculatorIfElse {
	
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		
		System.out.println("输入一个算术符号（+、-、*、/、%）：");
		String sign=input.next();
	
		System.out.println("输入第一个数字：");
		int first=input.nextInt();
		
		System.out.println("输入第二个数字：");
		int second=input.nextInt();
	
		input.close();
		
		int p=cal(sign,first,second);
		System.out.println(first+sign+second+"="+p);
	}
	
	public static int cal(String sign,int first,int second){
		int resualt=0;
		if(sign.equals("+")){
			resualt=first+second;
		}else if(sign.equals("-")){
			resualt=first-second;
		}else if(sign.equals("*")){
			resualt=first*second;
		}else if(sign.equals("/")){
			if(second==0){
				return 0;
			}
			resualt=first/second;
		}else if(sign.equals("%")){
			if(second==0){
				return 0;
			}
			resualt=first%second;
		}
		return resualt;
	}
}
